package com.easylinkin.linkappapi.childhospital.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.easylinkin.linkappapi.childhospital.entity.DormitoryManageFloor;
import com.easylinkin.linkappapi.childhospital.service.DormitoryManageService;
import com.easylinkin.linkappapi.childhospital.vo.DormitoryManage;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.easylinkin.linkappapi.childhospital.vo.DormitoryHistoryUserVo;
import com.easylinkin.linkappapi.childhospital.vo.DormitoryManageSelectVo;
import com.easylinkin.linkappapi.childhospital.vo.IDCardVo;
import site.morn.boot.rest.RestPage;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @program: linkapp-group
 * @description: 儿童医院宿舍管理
 * @author: yanqiang
 * @create: 2024-03-10 17:01
 */
@RestController
@RequestMapping("/dormitoryManage")
public class DormitoryManageController extends ApiController {

    /**
     * 服务对象
     */
    @Resource
    private DormitoryManageService dormitoryManageService;

    /***
     * 宿舍管理列表查询
     * @return
     */
    @PostMapping("getDormitoryManageList")
    public RestMessage getDormitoryManageList(@RequestBody DormitoryManage dormitoryManage) {
        return  RestBuilders.successBuilder(dormitoryManageService.selectDormitoryManage(dormitoryManage)).build();
    }

    /**
     * 新增或修改宿舍  （原有的）
     * @param dorFloorList
     * @return
     */
    @PostMapping("insertDormitoryManage")
    public RestMessage insertOrUpdateDormitoryManage(@RequestBody List<DormitoryManageFloor> dorFloorList) {
        Assert.notNull(dorFloorList, "参数为空");
        dormitoryManageService.insertOrUpdateDormitoryManage(dorFloorList);
        return RestBuilders.successBuilder().message("success").build();
    }

    /**
     *  （原有的）
     * @param  dorFloorList dorFloorList
     * @return
     */
    @PostMapping("getDormitoryManageDetail")
    public RestMessage getDormitoryManageDetail(@RequestBody List<DormitoryManageFloor> dorFloorList) {
        Assert.notNull(dorFloorList, "参数为空");
        dormitoryManageService.insertOrUpdateDormitoryManage(dorFloorList);
        return RestBuilders.successBuilder().message("success").build();
    }

    /**
     * 宿舍条件查询
     * @param entity
     * @return
     */
    @PostMapping("getDormitoryInfo")
    public RestMessage getDormitoryInfo(@RequestBody DormitoryManageSelectVo entity) {
        return  RestBuilders.successBuilder(dormitoryManageService.getDormitoryInfo(entity)).build();
    }

    /**
     * 查询楼栋-楼层-宿舍-人员详情
     * @param entity
     * @return
     */
    @PostMapping("getDormitoryDetail")
    public RestMessage getDormitoryDetail(@RequestBody DormitoryManageSelectVo entity) {
        return  RestBuilders.successBuilder(dormitoryManageService.getDormitoryDetail(entity)).build();
    }

    /**
     * 查询宿舍人员详情
     * @param roomId
     * @return
     */
    @PostMapping("getDormitoryUserInfo")
    public RestMessage getDormitoryUserInfo(String roomId, String keywords) {
        return  RestBuilders.successBuilder(dormitoryManageService.getDormitoryUserInfo(roomId, keywords)).build();
    }

    /**
     * 查询宿舍人员详情
     * @param restPage
     * @return
     */
    @PostMapping("getDormitoryUserHistory")
    public RestMessage getDormitoryUserHistory(@RequestBody RestPage<DormitoryHistoryUserVo> restPage) {
        return  RestBuilders.successBuilder(dormitoryManageService.getDormitoryUserHistory(restPage)).build();
    }

    /**
     * 新增宿舍
     * @param
     * @return
     */
    @PostMapping("insertDormitory")
    public RestMessage insertDormitory(@RequestBody Map<String,Object> json) {
        dormitoryManageService.insertDormitory(json);
        return  RestBuilders.successBuilder().message("success").build();
    }

    /**
     * 退房
     * @param userId
     * @return
     */
    @PostMapping("dormitoryCheckOut")
    public RestMessage dormitoryCheckOut(String userId) {
        dormitoryManageService.dormitoryCheckOut(userId);
        return  RestBuilders.successBuilder().message("success").build();
    }

    /**
     * 实名校验
     * @param entity
     * @return true 实名，false 未实名
     */
    @PostMapping("realNameCheck")
    public RestMessage realNameCheck(@RequestBody IDCardVo entity) {
        return  RestBuilders.successBuilder(dormitoryManageService.realNameCheck(entity)).build();
    }

    /**
     * 办理入住
     * @param entity
     * @return true 入住成功，false 未实名
     */
    @PostMapping("checkIn")
    public RestMessage checkIn(@RequestBody IDCardVo entity) {
        return  RestBuilders.successBuilder(dormitoryManageService.checkIn(entity)).build();
    }

    /**
     * 办理退房
     * @param userId
     * @param roomId
     * @return true 成功，false 失败
     */
    @PostMapping("checkOut")
    public RestMessage checkOut(String userId,String roomId) {
        dormitoryManageService.checkOut(userId,roomId);
        return  RestBuilders.successBuilder().message("退房成功").build();
    }

    /**
     * app首页统计
     * @return
     */
    @PostMapping("appCount")
    public RestMessage appCount(String floorId) {
        return  RestBuilders.successBuilder(dormitoryManageService.appCount(floorId)).build();
    }

    /**
     * app根据楼层查房间
     * @return
     */
    @PostMapping("appFindRoomUserByFloorId")
    public RestMessage appFindRoomUserByFloorId(String floorId) {
        return  RestBuilders.successBuilder(dormitoryManageService.appFindRoomUserByFloorId(floorId)).build();
    }
}
